unit TransferBill;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses,
  uniGUIClasses, uniGUIFrame, DB, DBClient, ClientRowSet, uniDateTimePicker,
  uniLabel, uniEdit, uniBasicGrid, uniDBGrid, uniButton, uniBitBtn,
  uniGUIBaseClasses, uniPanel, uniRadioButton;

type
  TFrmTransferBill = class(TUniFrame)
    UniPanel1: TUniPanel;
    btConfirm: TUniBitBtn;
    btNewTransfer: TUniBitBtn;
    GridBill: TUniDBGrid;
    dsTrsBill: TDataSource;
    crsTrsBill: TClientRowSet;
    crsTrsBillTRANS_ID: TStringField;
    crsTrsBillTRANS_NO: TStringField;
    crsTrsBillACCOUNT_NO: TStringField;
    crsTrsBillCOMPANY: TStringField;
    crsTrsBillPHONENO: TStringField;
    crsTrsBillCONTACTOR: TStringField;
    crsTrsBillADDRESS: TStringField;
    crsTrsBillBANK: TStringField;
    crsTrsBillBANK_ADDR: TStringField;
    crsTrsBillBANK_ACCOUNT: TStringField;
    crsTrsBillPAYABLE: TFloatField;
    crsTrsBillPAID: TFloatField;
    crsTrsBillCREATE_DATE: TStringField;
    crsTrsBillPAID_DATE: TStringField;
    crsTrsBillGROUP_CODE: TStringField;
    crsTrsBillNODE_NO: TStringField;
    crsTrsBillPAYER: TStringField;
    crsTrsBillSYS_ACCOUNT: TStringField;
    crsTrsBillBLANCE_MONTH: TStringField;
    crsTrsBillSTATE: TIntegerField;
    crsTrsBillREMARK: TStringField;
    crsTrsBillUPDATETIME: TStringField;
    crsTrsBillVERSION: TIntegerField;
    cbdate: TUniDateTimePicker;
    btFind: TUniBitBtn;
    edCust: TUniEdit;
    lbCust: TUniLabel;
    ckUnPay: TUniRadioButton;
    ckPaid: TUniRadioButton;
    procedure edCustEnter(Sender: TObject);
    procedure edCustExit(Sender: TObject);
    procedure lbCustClick(Sender: TObject);
    procedure btFindClick(Sender: TObject);
    procedure UniFrameCreate(Sender: TObject);
    procedure btNewTransferClick(Sender: TObject);
    procedure btConfirmClick(Sender: TObject);
  private
    { Private declarations }
  public

    { Public declarations }
    procedure InitForm;
    procedure ShowTransfer(condition:String);
  end;

implementation

{$R *.dfm}
uses expmodule,EditTransfer,PayTransBill;



{ TFrmTransferBill }

procedure TFrmTransferBill.btConfirmClick(Sender: TObject);
begin
  crsTrsBill.Edit;
  crsTrsBill.FieldByName('payer').AsString := dmexpress.UserInfo.UserName;
  FrmPayTransBill.dsTrans.DataSet := crsTrsBill;
  FrmPayTransBill.ShowModal;
end;

procedure TFrmTransferBill.btFindClick(Sender: TObject);
var
  condition:String;
begin
  condition := 'CREATE_DATE>=' + quotedstr(cbdate.Text);
  if ckUnPay.Checked then
    condition := condition + ' and state=0'
  else
    condition := condition + ' and state=1';

  if edcust.Text <> '' then
    condition := condition + ' and (CONTACTOR like ' + quotedstr(edcust.Text+'%') +
                             ' or PHONENO like ' + quotedstr(edcust.Text+'%') +
                             ' or COMPANY like '  + quotedstr(edcust.Text+'%') + ')';
  self.ShowTransfer(condition);
end;

procedure TFrmTransferBill.btNewTransferClick(Sender: TObject);
begin
  FrmEditTransfer.dsTrsBill.DataSet := crsTrsBill;
  FrmEditTransfer.BillData := nil;
  FrmEditTransfer.ShowModal;
end;

procedure TFrmTransferBill.edCustEnter(Sender: TObject);
begin
  lbCust.Visible := False;
end;

procedure TFrmTransferBill.edCustExit(Sender: TObject);
begin
  lbCust.Visible := edCust.Text = '';
end;

procedure TFrmTransferBill.InitForm;
begin
  cbdate.DateTime := date - 7;
  btfind.Click;
end;

procedure TFrmTransferBill.lbCustClick(Sender: TObject);
begin
  edcust.SetFocus;
end;

procedure TFrmTransferBill.ShowTransfer(condition: String);
var
  sqltxt:String;
begin
  sqltxt := 'select * from ACC_TRANSFER where ' +
            'sys_account=' + quotedstr(dmexpress.UserInfo.SysAccount);
  if condition <> '' then
    sqltxt := sqltxt + ' and ' + condition;
  dmexpress.OpenDataset(crsTrsBill,sqltxt);

end;

procedure TFrmTransferBill.UniFrameCreate(Sender: TObject);
begin
  InitForm;
end;

end.
